package cn.piggy.gateway.core.proxy.jdk;

import cn.piggy.gateway.core.proxy.MethodIntercept;
import cn.piggy.gateway.core.session.GatewaySession;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Map;

public class ObjectProxy implements InvocationHandler {
    private final GatewaySession gatewaySession;

    public ObjectProxy(GatewaySession gatewaySession) {
        this.gatewaySession = gatewaySession;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) {
        MethodIntercept linkMethod = new MethodIntercept(gatewaySession, (Map<String, Object>) args[0]);
//        Future<Object> queue = linkMethod.queue();
        Class<?> returnType = method.getReturnType();
        Object execute = linkMethod.execute();
        return returnType.cast(execute);
//        return linkMethod.execute();
    }
}
